/*
 * brief: 本模块作用作为发布订阅设计模式的服务端，创建服务端，等待客户端连接，接收数据包后解析并分发
 * use  : 1、实例化              CMsgInstanceServer    
 *        2、循环调度 调度函数    MsgServerSchedule
*/

#ifndef __MSGINSTANCESERVER_H_
#define __MSGINSTANCESERVER_H_


#include <iostream>
#include <stdio.h>
#include <deque>
#include <list>
#include <map>
#include <vector>
#include <stdarg.h>
#include "MsgEventID.h"
#include <time.h>
#include "Communication.h"
#include "ComLog.h"
#include <string.h>
#include "EventLoop.h"

using namespace std;


typedef struct MsgServerClientInfo_t
{
    int  clientfd;
    char clientaddr[40];
    int  clientport;
    time_t  lastkeepalivetime;
    char readbuf[6096];
    int validlen;
}MsgServerClientInfo;

class CMsgInstanceServer
{
   public:
     CMsgInstanceServer();
     ~CMsgInstanceServer();

     void MsgServerSchedule();
   
   private:
     map<int, map<int, void *> > m_eventList; //事件 socket句柄 保留数据
     map<int, MsgServerClientInfo> m_clientinfo; //socket句柄 socket信息
     CCommunication *m_Communi;//通信实例
     CEventLoop *m_eventloop; //epoll
     int m_serverfd; 
     int MsgCreateTCPServer();
     void MsgAcceptClietConnectCB(int fd, void *data); //接收连接的回调
     void MsgReadClietCB(int fd, void *data); //读取客户端数据的回调
     void MsgDistributePack(int fd, MsgPacket *msgPacket);
     MsgPacket *MsgConvertByteToMsgpacket(char *data, int datalen);
};




#endif